package com.projectw.controller;

import com.projectw.common.result.ResultMapper;
import com.projectw.common.util.SystemUtils;
import com.projectw.po.TestDemo;
import com.projectw.service.PwService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Peter_Wang on 2018/8/20.
 */
@RestController
@RequestMapping("/demo")
public class PwController {
    @Autowired
    private PwService pwService;

    @Autowired
    private SystemUtils systemUtils;


    /**
     * @param paramStr
     * @return
     */
    @RequestMapping("/get")
    public ResponseEntity<String> getDemo(@RequestParam("param") String paramStr){
        String result = this.pwService.selectTestDemo(paramStr);
        ResultMapper resultMapper = new ResultMapper();
        resultMapper.setData(result);
        resultMapper.setMark(ResultMapper.MARK_SUCCSSS);
        resultMapper.setMessage("查询成功");
        return SystemUtils.returnSuccessMsg(resultMapper);
    }
    /**
     * @param testDemo
     * @return
     */
    @RequestMapping("/create")
    public ResponseEntity<String> createDemo(@RequestBody TestDemo testDemo){
        boolean result = this.pwService.insertTestDemo(testDemo);
        ResultMapper resultMapper = new ResultMapper();
        resultMapper.setData(result);
        resultMapper.setMark(ResultMapper.MARK_SUCCSSS);
        resultMapper.setMessage("新增成功");
        return SystemUtils.returnSuccessMsg(resultMapper);
    }

    /**
     * @param testDemo
     * @return
     */
    @RequestMapping("/update")
    public ResponseEntity<String> updateDemo(@RequestBody TestDemo testDemo){
        boolean result = this.pwService.updateTestDemo(testDemo);
        ResultMapper resultMapper = new ResultMapper();
        resultMapper.setData(result);
        resultMapper.setMark(ResultMapper.MARK_SUCCSSS);
        resultMapper.setMessage("更新成功");
        return SystemUtils.returnSuccessMsg(resultMapper);
    }
}
